﻿#region "Copyright (C) Lenny Granovsky. 2005-2013"
//This program is free software distribute under the terms of the GNU General Public License as published by
//the Free Software Foundation. Please read AssemblyInfo.cs file for more information.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Web.Enhancements.Rest.Filters
{
    /// <summary>
    /// <para>Attribute that allows to set restriction on SSL requirement to REST service method.</para>
    /// <para>This attribute is an optional. By default SSL is required if attribute is set to the method.</para>
    /// </summary>
    [Serializable()]
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
    public class RequiresSslFilterAttribute : WebRestFilterAttribute
    {
        /// <summary>
        /// Gets or sets the if REST service method requires SSL.
        /// </summary>
        public bool RequiresSsl { get; set; }

        /// <summary>
        /// Default class constructor.
        /// </summary>
        public RequiresSslFilterAttribute()
            : base()
        {
            this.RequiresSsl = true;
        }

        /// <summary>
        /// Class constructor that accepts SSL requirement.
        /// </summary>
        /// <param name="requiresSsl">Boolean value indicated if SSL is required.</param>
        public RequiresSslFilterAttribute(bool requiresSsl)
            : base()
        {
            this.RequiresSsl = requiresSsl;
        }

        public override System.Type FilterType
        {
            get
            {
                return typeof(RequiresSslFilter);
            }
            set
            {
                //does nothing - should not reset value. //just for interface
            }
        }

        public override IWebRestFilter CreateFilter()
        {
            return new RequiresSslFilter()
            {
                RequiresSsl = this.RequiresSsl
            };
        }
    }
}
